package com.expand.learn.mybatis;

import com.expand.learn.model.Person;
import com.expand.learn.model.PersonDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description
 * @date 2020/3/10
 */
public class TestMybatis {

    public static void main(String[] args) throws IOException {

        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new
                SqlSessionFactoryBuilder().build(inputStream);
        inputStream.close();

        SqlSession session = sqlSessionFactory.openSession();
        final PersonDao mapper = session.getMapper(PersonDao.class);

        final Person person = mapper.selectPerson("qqq");

        System.out.println(person);
    }
}
